import os
from openai import OpenAI

def test1():
    client = OpenAI(
        api_key=os.getenv("ALIYUN-API-KEY"),  # 如果您没有配置环境变量，请在此处用您的API Key进行替换
        base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"  # 百炼服务的base_url
    )

    completion = client.embeddings.create(
        model="text-embedding-v3",#	1,024（默认）、768或512
        # dimensions=768,
        dimensions=1024,
        input=['风急天高猿啸哀', '渚清沙白鸟飞回', '无边落木萧萧下', '不尽长江滚滚来'],
        encoding_format="float"
    )


    print(completion.model_dump_json())



import dashscope
from http import HTTPStatus

def test2():
    resp = dashscope.TextEmbedding.call(
        model=dashscope.TextEmbedding.Models.text_embedding_v3,
        input='衣服的质量杠杠的，很漂亮，不枉我等了这么久啊，喜欢，以后还来这里买',
        dimension=1024, # 指定向量维度（仅 text-embedding-v3 支持该参数）
        output_type="dense&sparse"
    )

    print(resp) if resp.status_code == HTTPStatus.OK else print(resp)

# test1()
test2()
